
package Matrix;


public class Matrix {
	
	private double[][] matrix;
	
	public Matrix(double[][] matrix) {
		super();
		this.matrix = matrix;
	}
	
	public Matrix(int i, int j) {
		this.matrix = new double[i][j];
	}

	public Matrix() {
	}

	public int getRowCount() {
		int rows = this.matrix.length;
		return rows;
	}
	
	public int getColCount() {
		int columns = this.matrix[0].length;
		return columns;
	}

	public double getElement(int p, int q) {
		return this.matrix[p][q];
	}
	
	public void setElement(int p, int q, double element) {
		this.matrix[p][q]=element;
	}
	
	public static void toString(Matrix p) {
		for (int i=0; i==p.getRowCount(); i++) {
			System.out.println(" ");
			for (int j=0; j==p.getColCount(); j++) {
				System.out.print (p.getElement(i, j));
			}
		}
	}
	
	
	public Matrix multiplyTo(Matrix j) {
		int resultElement = 0;
		Matrix result = new Matrix(this.getColCount(), j.getRowCount());;
		
		if (this.getColCount() != j.getRowCount()) {
		throw new IllegalArgumentException("Sizes are incompatible for multiplication");
		
		} else { 
			for (int p = 0; p < j.getColCount(); p++)  {
				for (int q = 0; q < this.getRowCount(); q++) {
					for (int s = 0; s < j.getRowCount(); s++) {
						resultElement += this.getElement(p,s)*j.getElement(s,q);
					}
				result.setElement(p, q, resultElement);
				resultElement=0;
				}
	
	
	}
	}
		return result;
}
}

